# 给定一个列表, 根据grade来排序
classes_1 = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
classes_1.sort(key=lambda x: x["grade"])
print(classes_1)

# 通过filter语句来筛选出Grade为A的同学
classes_2 = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]
result = filter(lambda x: x["grade"] == "A", classes_2)
print(list(result))

# 通过map函数将上述同学的age + 1(对原数据结构有影响, 尽量不要用lambda)
classes_3 = [
    {"name": "n_1", "age": 24, "grade": "A"},
    {"name": "n_2", "age": 23, "grade": "B"},
    {"name": "n_3", "age": 28, "grade": "A"},
    {"name": "n_4", "age": 24, "grade": "A"},
    {"name": "n_5", "age": 25, "grade": "C"},
    {"name": "n_6", "age": 21, "grade": "D"},
    {"name": "n_7", "age": 27, "grade": "A"},
]


def age_add(a):
    a['age'] = a['age'] + 1
    return a


result = map(age_add, classes_3)
print(list(result))


def fab(n):
    if n == 0:
        return 0
    elif n == 1:
        return 1
    else:
        return fab(n - 1) + fab(n - 2)

for i in range(0, 12):
    print(fab(i))
